package com.lyl.syt.modules.mp.service.impl;/**
 * @author Mr.Luo
 * @date 2022-04-24 15:09
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyl.syt.common.exception.YyghException;
import com.lyl.syt.common.result.ResultCodeEnum;
import com.lyl.syt.model.hosp.HospitalSet;
import com.lyl.syt.modules.mp.dao.HospitalSetDao;
import com.lyl.syt.modules.mp.service.HospitalSetService;
import com.lyl.syt.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

/**
 * @author Mr.Luo
 * @date 2022-04-24 15:09
 * @desc 医院设置service实现类
 */
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetDao, HospitalSet> implements HospitalSetService {

    @Override
    public String getSignKey(String hoscode) {
        return lambdaQuery().eq(HospitalSet::getHoscode, hoscode)
                .oneOpt().orElse(new HospitalSet())
                .getSignKey();
    }

    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode", hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        if (null == hospitalSet) {
            throw new YyghException(ResultCodeEnum.HOSPITAL_OPEN);
        }
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;
    }
}
